package com.zhsj.OkeHomeConsumption.ui.activity;




import com.zhsj.OkeHomeConsumption.R;
import com.zhsj.OkeHomeConsumption.common.MyActivity;
import com.hjq.permissions.OnPermission;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;

import java.util.List;


/**
 * author : Xingdx
 * <p>
 * time   : 2018/10/18
 * desc   : 启动界面
 */
public final class LauncherActivity extends MyActivity
        implements OnPermission {




    @Override
    protected int getLayoutId() {
        return R.layout.activity_launcher;
    }

    @Override
    protected int getTitleId() {
        return 0;
    }

    @Override
    protected void initView() {
        if (XXPermissions.isHasPermission(LauncherActivity.this, Permission.Group.STORAGE)) {
            hasPermission(null, true);
        } else {
            requestPermission();
        }
    }

    private void requestPermission() {
        XXPermissions.with(this)
                .permission(Permission.Group.STORAGE)
                .permission(Permission.READ_PHONE_STATE)
                .permission(Permission.CAMERA)
                .request(this);
    }

    @Override
    protected void initData() {
    }

    private void yanshi(){

        new android.os.Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                startActivity(HomeActivity.class);
                finish();
            }
        },2000);
    }


    @Override
    public void noPermission(List<String> denied, boolean quick) {
        if (quick) {
            toast("没有权限访问文件，请手动授予权限");
            XXPermissions.gotoPermissionSettings(LauncherActivity.this, true);
        } else {
            toast("请先授予文件读写权限");
            postDelayed(new Runnable() {
                @Override
                public void run() {
                    requestPermission();
                }
            }, 1000);
        }
    }

    @Override
    public void onBackPressed() {
        //禁用返回键
        //super.onBackPressed();
    }

    @Override
    protected void onRestart() {
        super.onRestart();

    }

    @Override
    public void hasPermission(List<String> granted, boolean isAll) {
        yanshi();
    }


    @Override
    public boolean isSupportSwipeBack() {
        //不使用侧滑功能
        return false;
    }


    /**
     * Android 8.0踩坑记录：Only fullscreen opaque activities can request orientation
     * https://www.jianshu.com/p/d0d907754603
     */
    @Override
    protected void initOrientation() {
        // 注释父类的固定屏幕方向方法
        // super.initOrientation();
    }
}